Setup

Install Required Packages

If you don’t have the required packages installed, you can run the following code chunks to install them.

Install CRAN packages

install.packages(c("dplyr", "Seurat", "patchwork", "harmony", "tidyverse", "ggplot2"))

###Install Bioconductor packages

BiocManager::install(c("celldex", "SingleR", "scran"))

Load Required Packages

#Load necessary libraries for scRNA-seq analysis
library(dplyr)
library(Seurat)
library(patchwork)
library(harmony)
library(tidyverse)
library(ggplot2)
library(celldex)
library(SingleR)
library(scran)

Load Sample Data

Make sure your data folders contain the files named exactly as barcodes.tsv, features.tsv, and matrix.mtx because Read10X() expects these filenames.

# Load sample data using Read10X; adjust paths to where your files are stored
sam1 <- Read10X("~/Documents/Drive G/Personal Project/sc_RNAseq tutorial/sample/sample_1")
sam2 <- Read10X("~/Documents/Drive G/Personal Project/sc_RNAseq tutorial/sample/sample_2")

Convert the Files into Seurat Objects

Convert the raw data matrices into Seurat objects with minimum filtering criteria.

sam1 <- CreateSeuratObject(counts = sam1, min.cells = 3, min.features = 200, project = "sam1")
sam2 <- CreateSeuratObject(counts = sam2, min.cells= 3, min.features = 200, project ="sam2")

Calculate Mitochondrial Gene Percentage

sam1[["percent.mt"]] <- PercentageFeatureSet(sam1, pattern = "^MT-")
sam2[["percent.mt"]] <- PercentageFeatureSet(sam2, pattern = "^MT-")

# Uncomment to view metadata in RStudio's viewer
# View(sam1@meta.data)
# View(sam2@meta.data)

Visualize QC Metrics Before Filtering

#Violin Plots of QC Metrics
VlnPlot(sam1, features = c("nFeature_RNA", "nCount_RNA", "percent.mt"), ncol = 3) 

VlnPlot(sam2, features = c("nFeature_RNA", "nCount_RNA", "percent.mt"), ncol = 3) 

Note: These violin plots help assess data quality and guide you in determining appropriate parameters for quality control (QC) filtering.

Perform Quality Control (QC) Filtering

Here we subset the data to keep cells with:

sam1 <- subset(sam1, subset = nFeature_RNA > 200 & nFeature_RNA < 6500 & percent.mt < 15)
sam2 <- subset(sam2, subset = nFeature_RNA > 200 & nFeature_RNA < 6500 & percent.mt < 15)

Visualize QC Metrics After Filtering

The violin plots below show the distribution of features, counts, and mitochondrial content after QC filtering.

# Violin plots after QC filtering
VlnPlot(sam1, features = c("nFeature_RNA", "nCount_RNA", "percent.mt"), ncol = 3)

VlnPlot(sam2, features = c("nFeature_RNA", "nCount_RNA", "percent.mt"), ncol = 3)

## Merge Samples

Now that QC has been performed on each sample individually, we merge them into one Seurat object for downstream processing.

Merged_sam <- merge(sam1, sam2, add.cell.ids = c("sam1", "sam2"), project = "Merged_sam")

##Pre-processing

# Normalize the merged data
Merged_sam <- NormalizeData(Merged_sam, verbose = FALSE)

# Identify 2000 highly variable features
Merged_sam <- FindVariableFeatures(Merged_sam, selection.method = "vst", nfeatures = 2000, verbose = FALSE)

# Scale the data
Merged_sam <- ScaleData(Merged_sam, verbose = FALSE)

##Principal Component Analysis (PCA) We now perform PCA on the merged dataset to reduce dimensionality and visualize variance across principal components.

# Run PCA on the merged object
Merged_sam <- RunPCA(Merged_sam, verbose = FALSE)

# PCA plots
DimPlot(Merged_sam, reduction = "pca")

DimPlot(Merged_sam, reduction = "pca", dims = c(1, 5))

# Visualize PCA loadings
VizDimLoadings(Merged_sam, dims = 1:2, reduction = "pca")

## Run UMAP Before Harmony Integration

Merged_sam <- RunUMAP(Merged_sam, reduction = "pca", dims = 1:30, verbose = FALSE)
plot1 <- DimPlot(Merged_sam, reduction = "umap", group.by = "orig.ident", pt.size = 0.5) +
  ggtitle("UMAP Before Harmony Integration")

Run Harmony Integration

options(repr.plot.height = 2.5, repr.plot.width = 6)
Merged_sam <- RunHarmony(Merged_sam, "orig.ident", plot_convergence = TRUE, verbose = FALSE)

Run UMAP After Harmony Integration

Merged_sam <- RunUMAP(Merged_sam, reduction = "harmony", dims = 1:30,
                      reduction.name = "umap.harmony", verbose = FALSE)
plot2 <- DimPlot(Merged_sam, reduction = "umap.harmony", group.by = "orig.ident", pt.size = 0.5) +
  ggtitle("UMAP After Harmony Integration")

plot1 + plot2

### Run Clustering We use the Harmony reduction for neighbor detection and clustering. The resolution parameter controls cluster granularity:
- Higher resolution (e.g., 0.5) gives more clusters (finer granularity)
- Lower resolution (e.g., 0.1) gives fewer clusters (coarser granularity)

Merged_sam <- FindNeighbors(Merged_sam, reduction = "harmony", dims = 1:30, verbose = FALSE)
Merged_sam <- FindClusters(Merged_sam, resolution = 0.5, verbose = FALSE)
Merged_sam <- FindClusters(Merged_sam, resolution = 0.1, verbose = FALSE)

# Visualize clusters based on the lower-resolution clustering
DimPlot(Merged_sam, reduction = "umap.harmony",
  group.by = "RNA_snn_res.0.1", label.size = 2)

Find Marker Genes

Join Layers

We use JoinLayers() to consolidate data layers within the Seurat object. This ensures all assay-related information is accessible for downstream functions such as FindAllMarkers() and differential expression analysis, especially if the object was previously split or had multiple layers (e.g., when processed with newer Seurat versions or spatial datasets).

Merged_sam <- JoinLayers(Merged_sam)

Find Cluster-Specific Marker Genes

We identify marker genes that are upregulated in each cluster using FindAllMarkers().

Merged_sam.markers <- FindAllMarkers(Merged_sam, only.pos = TRUE, verbose = FALSE)

Filter Upregulated Marker Genes (avg_log2FC > 1)

We retain genes with an average log2 fold change > 1 and extract the top 10 upregulated genes per cluster.

top_markers <- Merged_sam.markers %>%
  group_by(cluster) %>%
  dplyr::filter(avg_log2FC > 1)

write.csv(top_markers, file = "top_markers.csv", row.names = FALSE)

top10 <- Merged_sam.markers %>%
  group_by(cluster) %>%
  dplyr::filter(avg_log2FC > 1) %>%
  slice_head(n = 10) %>%
  ungroup()

Visualize Marker Gene Expression

We visualize the expression of selected upregulated genes across clusters using FeaturePlot and summarize the expression of top 10 marker genes per cluster with a heatmap.

# Feature plots for selected upregulated genes
FeaturePlot(Merged_sam, features = c("S100P", "SLC11A1", "C1R", "KLRB1", "TRAC", 
                                     "NUSAP1", "HLA-DQB2", "TCL1A"))

# Heatmap of top 10 upregulated marker genes per cluster
DoHeatmap(Merged_sam, features = top10$gene) + NoLegend()

## Cell Type Annotation Using SingleR

Extract Normalized and Raw Counts

We extract the raw and normalized counts from the Seurat object for downstream SingleR analysis.

raw_counts <- LayerData(Merged_sam, assay = "RNA", layer = 'counts')
raw_counts[c("S100P", "SLC11A1", "C1R", "KLRB1", "TRAC"), 1:2]
## 5 x 2 sparse Matrix of class "dgCMatrix"
##         sam1_AAACCCAAGACGGTTG-1 sam1_AAACCCAAGGTCACAG-1
## S100P                         4                       .
## SLC11A1                       .                       .
## C1R                          34                       .
## KLRB1                         .                       .
## TRAC                          .                       .
norm_counts <- LayerData(Merged_sam, assay = "RNA", layer = 'data')
norm_counts[c("S100P", "SLC11A1", "C1R", "KLRB1", "TRAC"), 1:2]
## 5 x 2 sparse Matrix of class "dgCMatrix"
##         sam1_AAACCCAAGACGGTTG-1 sam1_AAACCCAAGGTCACAG-1
## S100P                  1.041993                       .
## SLC11A1                .                              .
## C1R                    2.809182                       .
## KLRB1                  .                              .
## TRAC                   .                              .

Load Reference Dataset from celldex

We use the Human Primary Cell Atlas as the reference dataset for cell type annotation.

ref <- celldex::HumanPrimaryCellAtlasData()
unique(ref$label.main)
##  [1] "DC"                   "Smooth_muscle_cells"  "Epithelial_cells"    
##  [4] "B_cell"               "Neutrophils"          "T_cells"             
##  [7] "Monocyte"             "Erythroblast"         "BM & Prog."          
## [10] "Endothelial_cells"    "Gametocytes"          "Neurons"             
## [13] "Keratinocytes"        "HSC_-G-CSF"           "Macrophage"          
## [16] "NK_cell"              "Embryonic_stem_cells" "Tissue_stem_cells"   
## [19] "Chondrocytes"         "Osteoblasts"          "BM"                  
## [22] "Platelets"            "Fibroblasts"          "iPS_cells"           
## [25] "Hepatocytes"          "MSC"                  "Neuroepithelial_cell"
## [28] "Astrocyte"            "HSC_CD34+"            "CMP"                 
## [31] "GMP"                  "MEP"                  "Myelocyte"           
## [34] "Pre-B_cell_CD34-"     "Pro-B_cell_CD34+"     "Pro-Myelocyte"
unique(ref$label.fine)
##   [1] "DC:monocyte-derived:immature"                          
##   [2] "DC:monocyte-derived:Galectin-1"                        
##   [3] "DC:monocyte-derived:LPS"                               
##   [4] "DC:monocyte-derived"                                   
##   [5] "Smooth_muscle_cells:bronchial:vit_D"                   
##   [6] "Smooth_muscle_cells:bronchial"                         
##   [7] "Epithelial_cells:bronchial"                            
##   [8] "B_cell"                                                
##   [9] "Neutrophil"                                            
##  [10] "T_cell:CD8+_Central_memory"                            
##  [11] "T_cell:CD8+"                                           
##  [12] "T_cell:CD4+"                                           
##  [13] "T_cell:CD8+_effector_memory_RA"                        
##  [14] "T_cell:CD8+_effector_memory"                           
##  [15] "T_cell:CD8+_naive"                                     
##  [16] "Monocyte"                                              
##  [17] "Erythroblast"                                          
##  [18] "BM"                                                    
##  [19] "DC:monocyte-derived:rosiglitazone"                     
##  [20] "DC:monocyte-derived:AM580"                             
##  [21] "DC:monocyte-derived:rosiglitazone/AGN193109"           
##  [22] "DC:monocyte-derived:anti-DC-SIGN_2h"                   
##  [23] "Endothelial_cells:HUVEC"                               
##  [24] "Endothelial_cells:HUVEC:Borrelia_burgdorferi"          
##  [25] "Endothelial_cells:HUVEC:IFNg"                          
##  [26] "Endothelial_cells:lymphatic"                           
##  [27] "Endothelial_cells:HUVEC:Serum_Amyloid_A"               
##  [28] "Endothelial_cells:lymphatic:TNFa_48h"                  
##  [29] "T_cell:effector"                                       
##  [30] "T_cell:CCR10+CLA+1,25(OH)2_vit_D3/IL-12"               
##  [31] "T_cell:CCR10-CLA+1,25(OH)2_vit_D3/IL-12"               
##  [32] "Gametocytes:spermatocyte"                              
##  [33] "DC:monocyte-derived:A._fumigatus_germ_tubes_6h"        
##  [34] "Neurons:ES_cell-derived_neural_precursor"              
##  [35] "Keratinocytes"                                         
##  [36] "Keratinocytes:IL19"                                    
##  [37] "Keratinocytes:IL20"                                    
##  [38] "Keratinocytes:IL22"                                    
##  [39] "Keratinocytes:IL24"                                    
##  [40] "Keratinocytes:IL26"                                    
##  [41] "Keratinocytes:KGF"                                     
##  [42] "Keratinocytes:IFNg"                                    
##  [43] "Keratinocytes:IL1b"                                    
##  [44] "HSC_-G-CSF"                                            
##  [45] "DC:monocyte-derived:mature"                            
##  [46] "Monocyte:anti-FcgRIIB"                                 
##  [47] "Macrophage:monocyte-derived:IL-4/cntrl"                
##  [48] "Macrophage:monocyte-derived:IL-4/Dex/cntrl"            
##  [49] "Macrophage:monocyte-derived:IL-4/Dex/TGFb"             
##  [50] "Macrophage:monocyte-derived:IL-4/TGFb"                 
##  [51] "Monocyte:leukotriene_D4"                               
##  [52] "NK_cell"                                               
##  [53] "NK_cell:IL2"                                           
##  [54] "Embryonic_stem_cells"                                  
##  [55] "Tissue_stem_cells:iliac_MSC"                           
##  [56] "Chondrocytes:MSC-derived"                              
##  [57] "Osteoblasts"                                           
##  [58] "Tissue_stem_cells:BM_MSC"                              
##  [59] "Osteoblasts:BMP2"                                      
##  [60] "Tissue_stem_cells:BM_MSC:BMP2"                         
##  [61] "Tissue_stem_cells:BM_MSC:TGFb3"                        
##  [62] "DC:monocyte-derived:Poly(IC)"                          
##  [63] "DC:monocyte-derived:CD40L"                             
##  [64] "DC:monocyte-derived:Schuler_treatment"                 
##  [65] "DC:monocyte-derived:antiCD40/VAF347"                   
##  [66] "Tissue_stem_cells:dental_pulp"                         
##  [67] "T_cell:CD4+_central_memory"                            
##  [68] "T_cell:CD4+_effector_memory"                           
##  [69] "T_cell:CD4+_Naive"                                     
##  [70] "Smooth_muscle_cells:vascular"                          
##  [71] "Smooth_muscle_cells:vascular:IL-17"                    
##  [72] "Platelets"                                             
##  [73] "Epithelial_cells:bladder"                              
##  [74] "Macrophage:monocyte-derived"                           
##  [75] "Macrophage:monocyte-derived:M-CSF"                     
##  [76] "Macrophage:monocyte-derived:M-CSF/IFNg"                
##  [77] "Macrophage:monocyte-derived:M-CSF/Pam3Cys"             
##  [78] "Macrophage:monocyte-derived:M-CSF/IFNg/Pam3Cys"        
##  [79] "Macrophage:monocyte-derived:IFNa"                      
##  [80] "Gametocytes:oocyte"                                    
##  [81] "Monocyte:F._tularensis_novicida"                       
##  [82] "Endothelial_cells:HUVEC:B._anthracis_LT"               
##  [83] "B_cell:Germinal_center"                                
##  [84] "B_cell:Plasma_cell"                                    
##  [85] "B_cell:Naive"                                          
##  [86] "B_cell:Memory"                                         
##  [87] "DC:monocyte-derived:AEC-conditioned"                   
##  [88] "Tissue_stem_cells:lipoma-derived_MSC"                  
##  [89] "Tissue_stem_cells:adipose-derived_MSC_AM3"             
##  [90] "Endothelial_cells:HUVEC:FPV-infected"                  
##  [91] "Endothelial_cells:HUVEC:PR8-infected"                  
##  [92] "Endothelial_cells:HUVEC:H5N1-infected"                 
##  [93] "Macrophage:monocyte-derived:S._aureus"                 
##  [94] "Fibroblasts:foreskin"                                  
##  [95] "iPS_cells:skin_fibroblast-derived"                     
##  [96] "iPS_cells:skin_fibroblast"                             
##  [97] "T_cell:gamma-delta"                                    
##  [98] "Monocyte:CD14+"                                        
##  [99] "Macrophage:Alveolar"                                   
## [100] "Macrophage:Alveolar:B._anthacis_spores"                
## [101] "Neutrophil:inflam"                                     
## [102] "iPS_cells:PDB_fibroblasts"                             
## [103] "iPS_cells:PDB_1lox-17Puro-5"                           
## [104] "iPS_cells:PDB_1lox-17Puro-10"                          
## [105] "iPS_cells:PDB_1lox-21Puro-20"                          
## [106] "iPS_cells:PDB_1lox-21Puro-26"                          
## [107] "iPS_cells:PDB_2lox-5"                                  
## [108] "iPS_cells:PDB_2lox-22"                                 
## [109] "iPS_cells:PDB_2lox-21"                                 
## [110] "iPS_cells:PDB_2lox-17"                                 
## [111] "iPS_cells:CRL2097_foreskin"                            
## [112] "iPS_cells:CRL2097_foreskin-derived:d20_hepatic_diff"   
## [113] "iPS_cells:CRL2097_foreskin-derived:undiff."            
## [114] "B_cell:CXCR4+_centroblast"                             
## [115] "B_cell:CXCR4-_centrocyte"                              
## [116] "Endothelial_cells:HUVEC:VEGF"                          
## [117] "iPS_cells:fibroblasts"                                 
## [118] "iPS_cells:fibroblast-derived:Direct_del._reprog"       
## [119] "iPS_cells:fibroblast-derived:Retroviral_transf"        
## [120] "Endothelial_cells:lymphatic:KSHV"                      
## [121] "Endothelial_cells:blood_vessel"                        
## [122] "Monocyte:CD16-"                                        
## [123] "Monocyte:CD16+"                                        
## [124] "Tissue_stem_cells:BM_MSC:osteogenic"                   
## [125] "Hepatocytes"                                           
## [126] "Neutrophil:uropathogenic_E._coli_UTI89"                
## [127] "Neutrophil:commensal_E._coli_MG1655"                   
## [128] "MSC"                                                   
## [129] "Neuroepithelial_cell:ESC-derived"                      
## [130] "Astrocyte:Embryonic_stem_cell-derived"                 
## [131] "Endothelial_cells:HUVEC:IL-1b"                         
## [132] "HSC_CD34+"                                             
## [133] "CMP"                                                   
## [134] "GMP"                                                   
## [135] "B_cell:immature"                                       
## [136] "MEP"                                                   
## [137] "Myelocyte"                                             
## [138] "Pre-B_cell_CD34-"                                      
## [139] "Pro-B_cell_CD34+"                                      
## [140] "Pro-Myelocyte"                                         
## [141] "Smooth_muscle_cells:umbilical_vein"                    
## [142] "iPS_cells:foreskin_fibrobasts"                         
## [143] "iPS_cells:iPS:minicircle-derived"                      
## [144] "iPS_cells:adipose_stem_cells"                          
## [145] "iPS_cells:adipose_stem_cell-derived:lentiviral"        
## [146] "iPS_cells:adipose_stem_cell-derived:minicircle-derived"
## [147] "Fibroblasts:breast"                                    
## [148] "Monocyte:MCSF"                                         
## [149] "Monocyte:CXCL4"                                        
## [150] "Neurons:adrenal_medulla_cell_line"                     
## [151] "Tissue_stem_cells:CD326-CD56+"                         
## [152] "NK_cell:CD56hiCD62L+"                                  
## [153] "T_cell:Treg:Naive"                                     
## [154] "Neutrophil:LPS"                                        
## [155] "Neutrophil:GM-CSF_IFNg"                                
## [156] "Monocyte:S._typhimurium_flagellin"                     
## [157] "Neurons:Schwann_cell"

Run SingleR for Cell Type Annotation

We run SingleR using normalized counts and the reference dataset to predict cell types.

ct_ann <- SingleR(test = norm_counts, # alternatively use raw_counts or SingleCellExperiment
                  ref = ref,
                  labels = ref$label.main,
                  de.method = 'wilcox')

Explore Annotation Results

head(ct_ann)
## DataFrame with 6 rows and 4 columns
##                                                 scores           labels
##                                               <matrix>      <character>
## sam1_AAACCCAAGACGGTTG-1 0.403145:0.345071:0.349268:...     Chondrocytes
## sam1_AAACCCAAGGTCACAG-1 0.166320:0.188311:0.200635:...       Macrophage
## sam1_AAACCCAAGTGCGTCC-1 0.173666:0.196706:0.213181:... Pre-B_cell_CD34-
## sam1_AAACCCACACGCTATA-1 0.127044:0.168634:0.181017:...               DC
## sam1_AAACCCAGTTTCCCAC-1 0.161358:0.172904:0.179275:...       Macrophage
## sam1_AAACCCATCTTGATTC-1 0.201712:0.266665:0.320877:...       Macrophage
##                          delta.next    pruned.labels
##                           <numeric>      <character>
## sam1_AAACCCAAGACGGTTG-1 0.053144843     Chondrocytes
## sam1_AAACCCAAGGTCACAG-1 0.004849993       Macrophage
## sam1_AAACCCAAGTGCGTCC-1 0.000941892 Pre-B_cell_CD34-
## sam1_AAACCCACACGCTATA-1 0.002488869               DC
## sam1_AAACCCAGTTTCCCAC-1 0.001034198       Macrophage
## sam1_AAACCCATCTTGATTC-1 0.204236805       Macrophage
unique(ct_ann$pruned.labels)
##  [1] "Chondrocytes"         "Macrophage"           "Pre-B_cell_CD34-"    
##  [4] "DC"                   "Fibroblasts"          "Pro-B_cell_CD34+"    
##  [7] "Epithelial_cells"     "GMP"                  "MSC"                 
## [10] "T_cells"              "B_cell"               "NK_cell"             
## [13] "Hepatocytes"          "HSC_-G-CSF"           "Monocyte"            
## [16] "Smooth_muscle_cells"  "HSC_CD34+"            "Endothelial_cells"   
## [19] NA                     "Pro-Myelocyte"        "Neutrophils"         
## [22] "Platelets"            "Osteoblasts"          "Keratinocytes"       
## [25] "Tissue_stem_cells"    "Embryonic_stem_cells" "Neurons"             
## [28] "CMP"                  "Myelocyte"            "iPS_cells"           
## [31] "Neuroepithelial_cell" "BM"                   "Astrocyte"           
## [34] "BM & Prog."           "Erythroblast"         "MEP"                 
## [37] "Gametocytes"
table(ct_ann$pruned.labels)
## 
##            Astrocyte               B_cell                   BM 
##                    5                   70                  148 
##           BM & Prog.         Chondrocytes                  CMP 
##                   13                  129                  152 
##                   DC Embryonic_stem_cells    Endothelial_cells 
##                  441                   21                   78 
##     Epithelial_cells         Erythroblast          Fibroblasts 
##                 1648                    4                  700 
##          Gametocytes                  GMP          Hepatocytes 
##                    1                  182                  135 
##           HSC_-G-CSF            HSC_CD34+            iPS_cells 
##                  182                   53                    9 
##        Keratinocytes           Macrophage                  MEP 
##                   56                 2964                    8 
##             Monocyte                  MSC            Myelocyte 
##                  312                  219                   26 
## Neuroepithelial_cell              Neurons          Neutrophils 
##                    7                   33                   16 
##              NK_cell          Osteoblasts            Platelets 
##                 1367                   15                    6 
##     Pre-B_cell_CD34-     Pro-B_cell_CD34+        Pro-Myelocyte 
##                  515                   97                  108 
##  Smooth_muscle_cells              T_cells    Tissue_stem_cells 
##                  935                 1436                   33
print("All labels:")
## [1] "All labels:"
table(ct_ann$labels)
## 
##            Astrocyte               B_cell                   BM 
##                    6                   70                  148 
##           BM & Prog.         Chondrocytes                  CMP 
##                   13                  139                  152 
##                   DC Embryonic_stem_cells    Endothelial_cells 
##                  441                   21                   79 
##     Epithelial_cells         Erythroblast          Fibroblasts 
##                 1648                    4                  758 
##          Gametocytes                  GMP          Hepatocytes 
##                    1                  182                  135 
##           HSC_-G-CSF            HSC_CD34+            iPS_cells 
##                  182                   53                    9 
##        Keratinocytes           Macrophage                  MEP 
##                   56                 3004                    9 
##             Monocyte                  MSC            Myelocyte 
##                  312                  226                   26 
## Neuroepithelial_cell              Neurons          Neutrophils 
##                    7                   33                   16 
##              NK_cell          Osteoblasts            Platelets 
##                 1367                   19                    7 
##     Pre-B_cell_CD34-     Pro-B_cell_CD34+        Pro-Myelocyte 
##                  515                   97                  110 
##  Smooth_muscle_cells              T_cells    Tissue_stem_cells 
##                  998                 1439                   33
summary(is.na(ct_ann$pruned.labels))
##    Mode   FALSE    TRUE 
## logical   12124     191

Visualization of SingleR Scores

plotScoreHeatmap(ct_ann)

plotDeltaDistribution(ct_ann, ncol = 4, dots.on.top = FALSE)

Add SingleR Labels to Seurat Object Metadata

We add the pruned SingleR labels to the Seurat object metadata for visualization.

rownames(ct_ann)[1:2] # verify cell IDs
## [1] "sam1_AAACCCAAGACGGTTG-1" "sam1_AAACCCAAGGTCACAG-1"
Merged_sam <- AddMetaData(Merged_sam, ct_ann$pruned.labels, col.name = 'SingleR_HCA')

Visualize Cell Type Annotations on UMAP

Merged_sam <- SetIdent(Merged_sam, value = "SingleR_HCA")
DimPlot(Merged_sam, label = TRUE, repel = TRUE, label.size = 3) + NoLegend()

Session Info

## ─ Session info ───────────────────────────────────────────────────────────────
##  setting  value
##  version  R version 4.4.0 (2024-04-24)
##  os       macOS 15.5
##  system   x86_64, darwin20
##  ui       X11
##  language (EN)
##  collate  en_US.UTF-8
##  ctype    en_US.UTF-8
##  tz       America/New_York
##  date     2025-05-29
##  pandoc   3.2 @ /Applications/RStudio.app/Contents/Resources/app/quarto/bin/tools/x86_64/ (via rmarkdown)
##  quarto   1.5.57 @ /Applications/RStudio.app/Contents/Resources/app/quarto/bin/quarto
## 
## ─ Packages ───────────────────────────────────────────────────────────────────
##  package              * version  date (UTC) lib source
##  abind                  1.4-8    2024-09-12 [1] CRAN (R 4.4.1)
##  alabaster.base         1.6.1    2024-11-10 [1] Bioconductor 3.20 (R 4.4.1)
##  alabaster.matrix       1.6.1    2024-11-20 [1] Bioconductor 3.20 (R 4.4.2)
##  alabaster.ranges       1.6.0    2024-10-29 [1] Bioconductor 3.20 (R 4.4.1)
##  alabaster.schemas      1.6.0    2024-10-29 [1] Bioconductor 3.20 (R 4.4.1)
##  alabaster.se           1.6.0    2024-10-29 [1] Bioconductor 3.20 (R 4.4.1)
##  AnnotationDbi          1.68.0   2024-10-29 [1] Bioconductor 3.20 (R 4.4.1)
##  AnnotationHub          3.14.0   2024-10-29 [1] Bioconductor 3.20 (R 4.4.1)
##  beachmat               2.22.0   2024-10-29 [1] Bioconductor 3.20 (R 4.4.1)
##  Biobase              * 2.66.0   2024-10-29 [1] Bioconductor 3.20 (R 4.4.1)
##  BiocFileCache          2.14.0   2024-10-29 [1] Bioconductor 3.20 (R 4.4.1)
##  BiocGenerics         * 0.52.0   2024-10-29 [1] Bioconductor 3.20 (R 4.4.1)
##  BiocManager            1.30.25  2024-08-28 [1] CRAN (R 4.4.1)
##  BiocNeighbors          2.0.1    2024-11-28 [1] Bioconductor 3.20 (R 4.4.2)
##  BiocParallel           1.40.2   2025-04-08 [1] Bioconductor
##  BiocSingular           1.22.0   2024-10-29 [1] Bioconductor 3.20 (R 4.4.1)
##  BiocVersion            3.20.0   2024-10-21 [1] Bioconductor 3.20 (R 4.4.1)
##  Biostrings             2.74.1   2024-12-16 [1] Bioconductor 3.20 (R 4.4.2)
##  bit                    4.6.0    2025-03-06 [1] CRAN (R 4.4.1)
##  bit64                  4.6.0-1  2025-01-16 [1] CRAN (R 4.4.1)
##  blob                   1.2.4    2023-03-17 [1] CRAN (R 4.4.0)
##  bluster                1.16.0   2024-10-29 [1] Bioconductor 3.20 (R 4.4.1)
##  bslib                  0.9.0    2025-01-30 [1] CRAN (R 4.4.1)
##  cachem                 1.1.0    2024-05-16 [1] CRAN (R 4.4.0)
##  celldex              * 1.16.0   2024-10-31 [1] Bioconductor 3.20 (R 4.4.0)
##  cli                    3.6.5    2025-04-23 [1] CRAN (R 4.4.1)
##  cluster                2.1.8.1  2025-03-12 [1] CRAN (R 4.4.1)
##  codetools              0.2-20   2024-03-31 [1] CRAN (R 4.4.0)
##  colorspace             2.1-1    2024-07-26 [1] CRAN (R 4.4.0)
##  cowplot                1.1.3    2024-01-22 [1] CRAN (R 4.4.0)
##  crayon                 1.5.3    2024-06-20 [1] CRAN (R 4.4.0)
##  curl                   6.2.2    2025-03-24 [1] CRAN (R 4.4.1)
##  data.table             1.17.0   2025-02-22 [1] CRAN (R 4.4.1)
##  DBI                    1.2.3    2024-06-02 [1] CRAN (R 4.4.0)
##  dbplyr                 2.5.0    2024-03-19 [1] CRAN (R 4.4.0)
##  DelayedArray           0.32.0   2024-10-29 [1] Bioconductor 3.20 (R 4.4.1)
##  DelayedMatrixStats     1.28.1   2025-01-09 [1] Bioconductor 3.20 (R 4.4.2)
##  deldir                 2.0-4    2024-02-28 [1] CRAN (R 4.4.0)
##  digest                 0.6.37   2024-08-19 [1] CRAN (R 4.4.1)
##  dotCall64              1.2      2024-10-04 [1] CRAN (R 4.4.1)
##  dplyr                * 1.1.4    2023-11-17 [1] CRAN (R 4.4.0)
##  dqrng                  0.4.1    2024-05-28 [1] CRAN (R 4.4.0)
##  edgeR                  4.4.2    2025-01-27 [1] Bioconductor 3.20 (R 4.4.2)
##  evaluate               1.0.3    2025-01-10 [1] CRAN (R 4.4.1)
##  ExperimentHub          2.14.0   2024-10-29 [1] Bioconductor 3.20 (R 4.4.1)
##  farver                 2.1.2    2024-05-13 [1] CRAN (R 4.4.0)
##  fastDummies            1.7.5    2025-01-20 [1] CRAN (R 4.4.1)
##  fastmap                1.2.0    2024-05-15 [1] CRAN (R 4.4.0)
##  filelock               1.0.3    2023-12-11 [1] CRAN (R 4.4.0)
##  fitdistrplus           1.2-2    2025-01-07 [1] CRAN (R 4.4.1)
##  forcats              * 1.0.0    2023-01-29 [1] CRAN (R 4.4.0)
##  future               * 1.40.0   2025-04-10 [1] CRAN (R 4.4.1)
##  future.apply           1.11.3   2024-10-27 [1] CRAN (R 4.4.1)
##  generics               0.1.3    2022-07-05 [1] CRAN (R 4.4.0)
##  GenomeInfoDb         * 1.42.3   2025-01-27 [1] Bioconductor 3.20 (R 4.4.2)
##  GenomeInfoDbData       1.2.13   2025-04-08 [1] Bioconductor
##  GenomicRanges        * 1.58.0   2024-10-29 [1] Bioconductor 3.20 (R 4.4.1)
##  ggplot2              * 3.5.2    2025-04-09 [1] CRAN (R 4.4.1)
##  ggrepel                0.9.6    2024-09-07 [1] CRAN (R 4.4.1)
##  ggridges               0.5.6    2024-01-23 [1] CRAN (R 4.4.0)
##  globals                0.17.0   2025-04-16 [1] CRAN (R 4.4.1)
##  glue                   1.8.0    2024-09-30 [1] CRAN (R 4.4.1)
##  goftest                1.2-3    2021-10-07 [1] CRAN (R 4.4.0)
##  gridExtra              2.3      2017-09-09 [1] CRAN (R 4.4.0)
##  gtable                 0.3.6    2024-10-25 [1] CRAN (R 4.4.1)
##  gypsum                 1.2.0    2024-10-29 [1] Bioconductor 3.20 (R 4.4.1)
##  harmony              * 1.2.3    2024-11-27 [1] CRAN (R 4.4.1)
##  HDF5Array              1.34.0   2024-10-29 [1] Bioconductor 3.20 (R 4.4.1)
##  hms                    1.1.3    2023-03-21 [1] CRAN (R 4.4.0)
##  htmltools              0.5.8.1  2024-04-04 [1] CRAN (R 4.4.0)
##  htmlwidgets            1.6.4    2023-12-06 [1] CRAN (R 4.4.0)
##  httpuv                 1.6.16   2025-04-16 [1] CRAN (R 4.4.1)
##  httr                   1.4.7    2023-08-15 [1] CRAN (R 4.4.0)
##  httr2                  1.1.2    2025-03-26 [1] CRAN (R 4.4.1)
##  ica                    1.0-3    2022-07-08 [1] CRAN (R 4.4.0)
##  igraph                 2.1.4    2025-01-23 [1] CRAN (R 4.4.1)
##  IRanges              * 2.40.1   2024-12-05 [1] Bioconductor 3.20 (R 4.4.2)
##  irlba                  2.3.5.1  2022-10-03 [1] CRAN (R 4.4.0)
##  jquerylib              0.1.4    2021-04-26 [1] CRAN (R 4.4.0)
##  jsonlite               2.0.0    2025-03-27 [1] CRAN (R 4.4.1)
##  KEGGREST               1.46.0   2024-10-29 [1] Bioconductor 3.20 (R 4.4.1)
##  KernSmooth             2.23-26  2025-01-01 [1] CRAN (R 4.4.1)
##  knitr                  1.50     2025-03-16 [1] CRAN (R 4.4.1)
##  labeling               0.4.3    2023-08-29 [1] CRAN (R 4.4.0)
##  later                  1.4.2    2025-04-08 [1] CRAN (R 4.4.1)
##  lattice                0.22-7   2025-04-02 [1] CRAN (R 4.4.1)
##  lazyeval               0.2.2    2019-03-15 [1] CRAN (R 4.4.0)
##  lifecycle              1.0.4    2023-11-07 [1] CRAN (R 4.4.0)
##  limma                  3.62.2   2025-01-09 [1] Bioconductor 3.20 (R 4.4.2)
##  listenv                0.9.1    2024-01-29 [1] CRAN (R 4.4.0)
##  lmtest                 0.9-40   2022-03-21 [1] CRAN (R 4.4.0)
##  locfit                 1.5-9.12 2025-03-05 [1] CRAN (R 4.4.1)
##  lubridate            * 1.9.4    2024-12-08 [1] CRAN (R 4.4.1)
##  magrittr               2.0.3    2022-03-30 [1] CRAN (R 4.4.0)
##  MASS                   7.3-65   2025-02-28 [1] CRAN (R 4.4.1)
##  Matrix                 1.7-3    2025-03-11 [1] CRAN (R 4.4.1)
##  MatrixGenerics       * 1.18.1   2025-01-09 [1] Bioconductor 3.20 (R 4.4.2)
##  matrixStats          * 1.5.0    2025-01-07 [1] CRAN (R 4.4.1)
##  memoise                2.0.1    2021-11-26 [1] CRAN (R 4.4.0)
##  metapod                1.14.0   2024-10-29 [1] Bioconductor 3.20 (R 4.4.1)
##  mime                   0.13     2025-03-17 [1] CRAN (R 4.4.1)
##  miniUI                 0.1.2    2025-04-17 [1] CRAN (R 4.4.1)
##  nlme                   3.1-168  2025-03-31 [1] CRAN (R 4.4.1)
##  parallelly             1.43.0   2025-03-24 [1] CRAN (R 4.4.1)
##  patchwork            * 1.3.0    2024-09-16 [1] CRAN (R 4.4.1)
##  pbapply                1.7-2    2023-06-27 [1] CRAN (R 4.4.0)
##  pheatmap               1.0.12   2019-01-04 [1] CRAN (R 4.4.0)
##  pillar                 1.10.2   2025-04-05 [1] CRAN (R 4.4.1)
##  pkgconfig              2.0.3    2019-09-22 [1] CRAN (R 4.4.0)
##  plotly                 4.10.4   2024-01-13 [1] CRAN (R 4.4.0)
##  plyr                   1.8.9    2023-10-02 [1] CRAN (R 4.4.0)
##  png                    0.1-8    2022-11-29 [1] CRAN (R 4.4.0)
##  polyclip               1.10-7   2024-07-23 [1] CRAN (R 4.4.0)
##  presto                 1.0.0    2025-01-08 [1] Github (immunogenomics/presto@7636b3d)
##  progressr              0.15.1   2024-11-22 [1] CRAN (R 4.4.1)
##  promises               1.3.2    2024-11-28 [1] CRAN (R 4.4.1)
##  purrr                * 1.0.4    2025-02-05 [1] CRAN (R 4.4.1)
##  R.methodsS3            1.8.2    2022-06-13 [1] CRAN (R 4.4.0)
##  R.oo                   1.27.1   2025-05-02 [1] CRAN (R 4.4.1)
##  R.utils                2.13.0   2025-02-24 [1] CRAN (R 4.4.1)
##  R6                     2.6.1    2025-02-15 [1] CRAN (R 4.4.1)
##  RANN                   2.6.2    2024-08-25 [1] CRAN (R 4.4.1)
##  rappdirs               0.3.3    2021-01-31 [1] CRAN (R 4.4.0)
##  RColorBrewer           1.1-3    2022-04-03 [1] CRAN (R 4.4.0)
##  Rcpp                 * 1.0.14   2025-01-12 [1] CRAN (R 4.4.1)
##  RcppAnnoy              0.0.22   2024-01-23 [1] CRAN (R 4.4.0)
##  RcppHNSW               0.6.0    2024-02-04 [1] CRAN (R 4.4.0)
##  readr                * 2.1.5    2024-01-10 [1] CRAN (R 4.4.0)
##  reshape2               1.4.4    2020-04-09 [1] CRAN (R 4.4.0)
##  reticulate             1.42.0   2025-03-25 [1] CRAN (R 4.4.1)
##  rhdf5                  2.50.2   2025-01-09 [1] Bioconductor 3.20 (R 4.4.2)
##  rhdf5filters           1.18.1   2025-03-06 [1] Bioconductor 3.20 (R 4.4.3)
##  Rhdf5lib               1.28.0   2024-10-29 [1] Bioconductor 3.20 (R 4.4.1)
##  RhpcBLASctl            0.23-42  2023-02-11 [1] CRAN (R 4.4.0)
##  rlang                  1.1.6    2025-04-11 [1] CRAN (R 4.4.1)
##  rmarkdown              2.29     2024-11-04 [1] CRAN (R 4.4.1)
##  ROCR                   1.0-11   2020-05-02 [1] CRAN (R 4.4.0)
##  RSpectra               0.16-2   2024-07-18 [1] CRAN (R 4.4.0)
##  RSQLite                2.3.11   2025-05-04 [1] CRAN (R 4.4.1)
##  rstudioapi             0.17.1   2024-10-22 [1] CRAN (R 4.4.1)
##  rsvd                   1.0.5    2021-04-16 [1] CRAN (R 4.4.0)
##  Rtsne                  0.17     2023-12-07 [1] CRAN (R 4.4.0)
##  S4Arrays               1.6.0    2024-10-29 [1] Bioconductor 3.20 (R 4.4.1)
##  S4Vectors            * 0.44.0   2024-10-29 [1] Bioconductor 3.20 (R 4.4.1)
##  sass                   0.4.10   2025-04-11 [1] CRAN (R 4.4.1)
##  ScaledMatrix           1.14.0   2024-10-29 [1] Bioconductor 3.20 (R 4.4.1)
##  scales                 1.4.0    2025-04-24 [1] CRAN (R 4.4.1)
##  scattermore            1.2      2023-06-12 [1] CRAN (R 4.4.0)
##  scran                * 1.34.0   2024-10-29 [1] Bioconductor 3.20 (R 4.4.1)
##  sctransform            0.4.2    2025-04-30 [1] CRAN (R 4.4.1)
##  scuttle              * 1.16.0   2024-10-29 [1] Bioconductor 3.20 (R 4.4.1)
##  sessioninfo            1.2.3    2025-02-05 [1] CRAN (R 4.4.1)
##  Seurat               * 5.3.0    2025-04-23 [1] CRAN (R 4.4.1)
##  SeuratObject         * 5.1.0    2025-04-22 [1] CRAN (R 4.4.1)
##  shiny                  1.10.0   2024-12-14 [1] CRAN (R 4.4.1)
##  SingleCellExperiment * 1.28.1   2024-11-10 [1] Bioconductor 3.20 (R 4.4.1)
##  SingleR              * 2.8.0    2024-10-29 [1] Bioconductor 3.20 (R 4.4.1)
##  sp                   * 2.2-0    2025-02-01 [1] CRAN (R 4.4.1)
##  spam                   2.11-1   2025-01-20 [1] CRAN (R 4.4.1)
##  SparseArray            1.6.2    2025-02-20 [1] Bioconductor 3.20 (R 4.4.2)
##  sparseMatrixStats      1.18.0   2024-10-29 [1] Bioconductor 3.20 (R 4.4.1)
##  spatstat.data          3.1-6    2025-03-17 [1] CRAN (R 4.4.1)
##  spatstat.explore       3.4-2    2025-03-21 [1] CRAN (R 4.4.1)
##  spatstat.geom          3.3-6    2025-03-18 [1] CRAN (R 4.4.1)
##  spatstat.random        3.3-3    2025-03-19 [1] CRAN (R 4.4.1)
##  spatstat.sparse        3.1-0    2024-06-21 [1] CRAN (R 4.4.0)
##  spatstat.univar        3.1-2    2025-03-05 [1] CRAN (R 4.4.1)
##  spatstat.utils         3.1-3    2025-03-15 [1] CRAN (R 4.4.1)
##  statmod                1.5.0    2023-01-06 [1] CRAN (R 4.4.0)
##  stringi                1.8.7    2025-03-27 [1] CRAN (R 4.4.1)
##  stringr              * 1.5.1    2023-11-14 [1] CRAN (R 4.4.0)
##  SummarizedExperiment * 1.36.0   2024-10-29 [1] Bioconductor 3.20 (R 4.4.1)
##  survival               3.8-3    2024-12-17 [1] CRAN (R 4.4.1)
##  tensor                 1.5      2012-05-05 [1] CRAN (R 4.4.0)
##  tibble               * 3.2.1    2023-03-20 [1] CRAN (R 4.4.0)
##  tidyr                * 1.3.1    2024-01-24 [1] CRAN (R 4.4.0)
##  tidyselect             1.2.1    2024-03-11 [1] CRAN (R 4.4.0)
##  tidyverse            * 2.0.0    2023-02-22 [1] CRAN (R 4.4.0)
##  timechange             0.3.0    2024-01-18 [1] CRAN (R 4.4.0)
##  tzdb                   0.5.0    2025-03-15 [1] CRAN (R 4.4.1)
##  UCSC.utils             1.2.0    2024-10-29 [1] Bioconductor 3.20 (R 4.4.1)
##  uwot                   0.2.3    2025-02-24 [1] CRAN (R 4.4.1)
##  vctrs                  0.6.5    2023-12-01 [1] CRAN (R 4.4.0)
##  viridis                0.6.5    2024-01-29 [1] CRAN (R 4.4.0)
##  viridisLite            0.4.2    2023-05-02 [1] CRAN (R 4.4.0)
##  withr                  3.0.2    2024-10-28 [1] CRAN (R 4.4.1)
##  xfun                   0.52     2025-04-02 [1] CRAN (R 4.4.1)
##  xtable                 1.8-4    2019-04-21 [1] CRAN (R 4.4.0)
##  XVector                0.46.0   2024-10-29 [1] Bioconductor 3.20 (R 4.4.1)
##  yaml                   2.3.10   2024-07-26 [1] CRAN (R 4.4.0)
##  zlibbioc               1.52.0   2024-10-29 [1] Bioconductor 3.20 (R 4.4.1)
##  zoo                    1.8-14   2025-04-10 [1] CRAN (R 4.4.1)
## 
##  [1] /Library/Frameworks/R.framework/Versions/4.4-x86_64/Resources/library
##  * ── Packages attached to the search path.
## 
## ──────────────────────────────────────────────────────────────────────────────